﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class FormSupplyBathroom : System.Windows.Forms.Form
	{
		public FormSupplyBathroom(HYPipeCal p)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.CenterToParent();
			base.Icon = Resource.YArchitechIcon;
			this.pipe = p;
			this.InitList();
			this.UptadaList();
		}

		private void InitList()
		{
			this.listViewBathroom.Columns.Add("", 0, HorizontalAlignment.Left);
			this.listViewBathroom.Columns.Add("卫生器具名称", 120, HorizontalAlignment.Left);
			this.listViewBathroom.Columns.Add("额定流量(L/s)", 110, HorizontalAlignment.Left);
			this.listViewBathroom.Columns.Add("同时给水百分数", 120, HorizontalAlignment.Left);
			this.listViewBathroom.notification = new EidtListView.DataChangedNotification(this.changeDataManually);
		}

		private void UptadaList()
		{
			this.listViewBathroom.Items.Clear();
			for (int i = 0; i < this.pipe.upBathroomArray.Count; i++)
			{
				HYBathroom hybathroom = this.pipe.upBathroomArray[i];
				ListViewItem listViewItem = new ListViewItem();
				listViewItem.Text = "";
				listViewItem.Tag = i;
				ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
				listViewSubItem.Text = hybathroom.szName;
				listViewItem.SubItems.Add(listViewSubItem);
				listViewSubItem = new ListViewItem.ListViewSubItem();
				listViewSubItem.Text = hybathroom.dSupplyFlow.ToString();
				listViewItem.SubItems.Add(listViewSubItem);
				string text = hybathroom.dPer.ToString();
				if (this.bathroomPerList.ContainsKey(i))
				{
					text = this.bathroomPerList[i].ToString();
				}
				listViewSubItem = new ListViewItem.ListViewSubItem();
				listViewSubItem.Text = text;
				listViewSubItem.Tag = 3;
				listViewItem.SubItems.Add(listViewSubItem);
				this.listViewBathroom.Items.Add(listViewItem);
			}
			this.listViewBathroom.Refresh();
		}

		private void changeDataManually(string text, int itemTag, int subItemTag)
		{
			bool flag = false;
			double value = 0.0;
			try
			{
				value = Convert.ToDouble(text);
				flag = true;
			}
			catch (Exception ex)
			{
				ex.ToString();
			}
			if (subItemTag != 3 || !flag)
			{
				return;
			}
			if (this.bathroomPerList.ContainsKey(itemTag))
			{
				this.bathroomPerList[itemTag] = value;
			}
			else
			{
				this.bathroomPerList.Add(itemTag, value);
			}
			this.UptadaList();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			try
			{
				foreach (KeyValuePair<int, double> keyValuePair in this.bathroomPerList)
				{
					this.pipe.upBathroomArray[keyValuePair.Key].dPer = keyValuePair.Value;
				}
			}
			catch
			{
			}
			base.DialogResult = DialogResult.OK;
			base.Close();
		}

		private void button2_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
			base.Close();
		}

		private HYPipeCal pipe;

		private Dictionary<int, double> bathroomPerList = new Dictionary<int, double>();
	}
}
